using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
using System.Web.UI;
using System.Web;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Text;
namespace LUM
{


    public class lum
    {

        public static void setProperty(ref object prop, System.Data.DataRow dr, string fieldNAme)
        {
            try
            {
                if (dr.Table.Columns.Contains(fieldNAme))
                {
                    if (!object.ReferenceEquals(dr[fieldNAme], DBNull.Value))
                    {
                        prop = dr[fieldNAme];
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error al asignar el valor", ex);
            }
        }

        public static void mensaje(string Mensaje)
        {
            //Mensaje = "window.alert('" + Mensaje.Replace("'", "\\'").Replace("\"", " \\\"") + "');";

            string[] animacionesEntrada = new string[69] { "bounceIn","bounceInDown","bounceInLeft","bounceInRight","bounceInUp","slideInDown",
                    "slideInLeft","slideInRight","slideInUp","fadeIn","fadeInDown","fadeInDownBig",
                    "fadeInLeft","fadeInLeftBig","fadeInRight","fadeInRightBig","fadeInUp","fadeInUpBig",
                    "flip","flipInX","flipInY","lightSpeedIn","rotateIn","rotateInDownLeft",
                    "rotateInDownRight","rotateInUpLeft","rotateInUpRight","bounce","flash","pulse",
                    "rubberBand","shake","swing","tada","wobble","rollIn",
                    "zoomIn","zoomInDown","zoomInLeft","zoomInRight","zoomInUp","bounceIn",
                    "bounceInDown","bounceInLeft","bounceInRight","bounceInUp","fadeIn","fadeInDown",
                    "fadeInDownBig","fadeInLeft","fadeInLeftBig","fadeInRight","fadeInRightBig","fadeInUp",
                    "fadeInUpBig","flipInX","flipInY","lightSpeedIn","rotateIn","rotateInDownLeft",
                    "rotateInDownRight","rotateInUpLeft","rotateInUpRight","rollIn","zoomIn","zoomInDown",
                    "zoomInLeft","zoomInRight","zoomInUp"
                    };
            string[] animacionesSalida = new string[62] { "bounceOut","bounceOutDown","bounceOutLeft","bounceOutRight","bounceOutUp","slideOutDown",
                    "slideOutLeft","slideOutRight","slideOutUp","fadeOut","fadeOutDown","fadeOutDownBig",
                    "fadeOutLeft","fadeOutLeftBig","fadeOutRight","fadeOutRightBig","fadeOutUp","fadeOutUpBig",
                    "flip","flipOutX","flipOutY","lightSpeedOut","rotateOut","rotateOutDownLeft",
                    "rotateOutDownRight","rotateOutUpLeft","rotateOutUpRight","hinge","rollOut","zoomOut",
                    "zoomOutDown","zoomOutLeft","zoomOutRight","zoomOutUp","bounceOut","bounceOutDown",
                    "bounceOutLeft","bounceOutRight","bounceOutUp","fadeOut","fadeOutDown","fadeOutDownBig",
                    "fadeOutLeft","fadeOutLeftBig","fadeOutRight","fadeOutRightBig","fadeOutUp","fadeOutUpBig",
                    "flipOutX","flipOutY","lightSpeedOut","rotateOut","rotateOutDownLeft","rotateOutDownRight",
                    "rotateOutUpLeft","rotateOutUpRight","rollOut","zoomOut","zoomOutDown","zoomOutLeft",
                    "zoomOutRight","zoomOutUp"
                    };


            Random rnd = new Random();
            int iAnimShow = rnd.Next(0, 69);
            int ianimHide = rnd.Next(0, 62);
            
            //Mensaje = "$.iGrowl({" +
            //            " type: 'info'," +
            //            " message: '" + Mensaje + "'," +
            //            " icon: 'vicons-cart'," +	
            //            " delay: 102500, " +
            //            " offset : {  y: 	50 }, " +
            //            " icon: 'feather-cog'," +	
            //            " small: true," +
            //            " placement[x]:	'center' ," +
            //            " animShow: '" + animaciones[iAnimShow] + "'," +
            //            " animHide: '" + animaciones[ianimHide] + "'" +
            //            "})      ";

           string script = "$.iGrowl({" +
" type: 'info'," +
" icon: 'vicons-envelope'," +
" message: '" + Mensaje + "'," +
" animShow: '" + animacionesEntrada[iAnimShow] + "'," +
" animHide: '" + animacionesSalida[ianimHide] + "'," +
" delay: 12000," +
" offset : {  y: 	50 } ," +
" placement: {  x: 	'center', y: 'top' } " +
"})";





            //Mensaje = "window.alert('" & Mensaje.Replace("'", "").Replace("""", "").Replace(vbLf, "\n") & "');"
            //Mensaje = "window.alert('hola');"
            if (HttpContext.Current.CurrentHandler is Page)
            {
                Page p = (Page)HttpContext.Current.CurrentHandler;
                if (ScriptManager.GetCurrent(p) != null)
                {
                    ScriptManager.RegisterStartupScript(p, typeof(Page), "Message", script, true);
                }
                else
                {
                    p.ClientScript.RegisterStartupScript(typeof(Page), "Message", script, true);
                }
            }
        }


        public static bool EsEmail(string email)
        {
            return Regex.IsMatch(email, "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", RegexOptions.IgnoreCase);
        }


        public static DateTime ObtenerFecha(int dia, int mes, int anio)
        {
            try
            {
                return new DateTime(anio, mes, dia);
            }
            catch
            {
                throw new Exception("Fecha Invalida");
            }


        }
        public static double RoundUp(double number, int decimalPlaces)
        {
            return Math.Ceiling(number * Math.Pow(10, decimalPlaces)) / Math.Pow(10, decimalPlaces);
        }

        public static Boolean IsNumeric(Object Expression)
        {
            if (Expression == null || Expression is DateTime)
                return false;

            if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
                return true;

            try
            {
                if (Expression is string)
                    Double.Parse(Expression as string);
                else
                    Double.Parse(Expression.ToString());
                return true;
            }
            catch { } // just dismiss errors but return false
            return false;
        }
    }

}
